home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / private / _queryad.c < prev    next >
C/C++ Source or Header  |  1993-06-20  |  6KB  |  293 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3. #ifdef UNIX
  4. #include <defs.h>
  5. #include <term.h>
  6. #endif
  7.  
  8. #ifdef PDCDEBUG
  9. char *rcsid__queryad = "$Header: C:\CURSES\private\RCS\_queryad.c 2.1 1993/06/18 20:22:33 MH Rel MH $";
  10. #endif
  11.  
  12.  
  13.  
  14.  
  15. /*man-start*********************************************************************
  16.  
  17.   PDC_query_adapter_type()    - Determine PC video adapter type
  18.  
  19.   PDCurses Description:
  20.      This is a private PDCurses routine.
  21.  
  22.      Thanks to Jeff Duntemann, K16RA for providing the impetus
  23.      (through the Dr. Dobbs Journal, March 1989 issue) for getting
  24.      the routines below merged into Bjorn Larsson's PDCurses 1.3...
  25.          -- frotz@dri.com    900730
  26.  
  27.   PDCurses Return Value:
  28.      This function returns a macro identifier indicating the adapter
  29.      type.  See the list of adapter types in PRIVATE/CURSPRIV.H.
  30.  
  31.   PDCurses Errors:
  32.      No errors are defined for this function.
  33.  
  34.   Portability:
  35.      PDCurses    int PDC_query_adapter_type( void );
  36.  
  37. **man-end**********************************************************************/
  38.  
  39. #ifdef     OS2
  40. VIOCONFIGINFO    PDC_query_adapter_type(void)
  41. #else
  42. int    PDC_query_adapter_type(void)
  43. #endif
  44. {
  45.     int    retval = _NONE;
  46.  
  47. #ifdef    DOS
  48.     int    equip;
  49.     struct SREGS segs;
  50.     short video_base = getdosmemword (0x463);
  51. #endif
  52.  
  53. #ifdef    OS2
  54.     VIOCONFIGINFO configInfo;
  55. #endif
  56.  
  57. #ifdef PDCDEBUG
  58.     if (trace_on) PDC_debug("PDC_query_adapter_type() - called\n");
  59. #endif
  60.  
  61. #ifdef    FLEXOS
  62.     return (_FLEXOS);
  63. #endif
  64.  
  65. #ifdef    DOS
  66.     /*
  67.      * Attempt to call VGA Identify Adapter Function...
  68.      */
  69.     regs.h.ah = 0x1a;
  70.     regs.h.al = 0;
  71.     int86(0x10, ®s, ®s);
  72.     if ((regs.h.al == 0x1a) && (retval == _NONE))
  73.     {
  74.         /*
  75.          * We know that the PS/2 video BIOS is alive and well.
  76.          */
  77.         switch (regs.h.al)
  78.         {
  79.         case 0:
  80.             retval = _NONE;
  81.             break;
  82.         case 1:
  83.             retval = _MDA;
  84.             break;
  85.         case 2:
  86.             retval = _CGA;
  87.             break;
  88.         case 4:
  89.             retval = _EGACOLOR;
  90.             _cursvar.sizeable = TRUE;
  91.             break;
  92.         case 5:
  93.             retval = _EGAMONO;
  94.             break;
  95.         case 26:
  96.             retval = _VGACOLOR;    /* ...alt. VGA BIOS... */
  97.         case 7:
  98.             retval = _VGACOLOR;
  99.             _cursvar.sizeable = TRUE;
  100.             break;
  101.         case 8:
  102.             retval = _VGAMONO;
  103.             break;
  104.         case 10:
  105.         case 13:
  106.             retval = _MCGACOLOR;
  107.             break;
  108.         case 12:
  109.             retval = _MCGAMONO;
  110.             break;
  111.         default:
  112.             retval = _CGA;
  113.             break;
  114.         }
  115.     }
  116.     else
  117.     {
  118.         /*
  119.          * No VGA BIOS, check for an EGA BIOS by selecting an
  120.          * Alternate Function Service...
  121.          *
  122.          * bx == 0x0010     -->  return EGA information
  123.          */
  124.         regs.h.ah = 0x12;
  125.         regs.x.bx = 0x10;
  126.         int86(0x10, ®s, ®s);
  127.         if ((regs.h.bl != 0x10) && (retval == _NONE))
  128.         {
  129.             /*
  130.              * An EGA BIOS exists...
  131.              */
  132.             regs.h.ah = 0x12;
  133.             regs.h.bl = 0x10;
  134.             int86(0x10, ®s, ®s);
  135.             if (regs.h.bh == 0)
  136.                 retval = _EGACOLOR;
  137.             else
  138.                 retval = _EGAMONO;
  139.         }
  140.         else
  141.         if (retval == _NONE)
  142.         {
  143.             /*
  144.              * Now we know we only have CGA or MDA...
  145.              */
  146.             int86(0x11, ®s, ®s);
  147.             equip = (regs.h.al & 0x30) >> 4;
  148.             switch (equip)
  149.             {
  150.             case 1:
  151.             case 2:
  152.                 retval = _CGA;
  153.                 break;
  154.             case 3:
  155.                 retval = _MDA;
  156.                 break;
  157.             default:
  158.                 retval = _NONE;
  159.                 break;
  160.             }
  161.         }
  162.     }
  163.     if (video_base == 0x3d4)
  164.     {
  165.         _cursvar.video_seg = 0xb800;
  166.         switch (retval)
  167.         {
  168.         case _EGAMONO:
  169.             retval = _EGACOLOR;
  170.             break;
  171.         case _VGAMONO:
  172.             retval = _VGACOLOR;
  173.             break;
  174.         default:
  175.             break;
  176.         }
  177.     }
  178.     if (video_base == 0x3b4)
  179.     {
  180.         _cursvar.video_seg = 0xb000;
  181.         switch (retval)
  182.         {
  183.         case _EGACOLOR:
  184.             retval = _EGAMONO;
  185.             break;
  186.         case _VGACOLOR:
  187.             retval = _VGAMONO;
  188.             break;
  189.         default:
  190.             break;
  191.         }
  192.     }
  193.     if ((retval == _NONE)
  194. #ifndef CGA_DIRECT
  195.     ||  (retval == _CGA)
  196. #endif
  197.     )
  198.     {
  199.         _cursvar.direct_video = FALSE;
  200.     }
  201.     if ((unsigned int) _cursvar.video_seg == 0xb000)
  202.         _cursvar.mono = TRUE;
  203.     else
  204.         _cursvar.mono = FALSE;
  205.  
  206.     regs.h.ah = 0xfe;        /* Check for DESQview shadow buffer */
  207.     regs.h.al = 0;
  208.     regs.x.di = _cursvar.video_ofs;
  209.     segs.es   = _cursvar.video_seg;
  210.     int86x(0x10, ®s, ®s, &segs);
  211.     _cursvar.video_ofs = regs.x.di;
  212.     _cursvar.video_seg = segs.es;
  213.  
  214.     if  (!_cursvar.adapter)
  215.         _cursvar.adapter = retval;
  216.     return (PDC_sanity_check(retval));
  217. #endif
  218.  
  219. #ifdef    OS2
  220.     VioGetConfig(0, &configInfo, 0);
  221.     _cursvar.sizeable = TRUE;
  222.         return configInfo;
  223. #  if     0
  224.     switch (configInfo.adapter)
  225.     {
  226.         case 0:
  227.             retval = _MDA;
  228.             _cursvar.mono =TRUE;
  229.             break;
  230.         case 1:
  231.             retval = _CGA;
  232.             _cursvar.mono = FALSE;
  233.             break;
  234.         case 2: switch (configInfo.display)
  235.             {
  236.                 case 0:
  237.                 case 3:
  238.                     retval = _EGAMONO;
  239.                     _cursvar.mono = TRUE;
  240.                     break;
  241.                 case 1:
  242.                 case 2:
  243.                 case 4:
  244.                 case 9:
  245.                     retval = _EGACOLOR;
  246.                     _cursvar.mono = FALSE;
  247.                     break;
  248.             }
  249.             break;
  250.         case 3: switch (configInfo.display)
  251.             {
  252.                 case 0:
  253.                 case 3:
  254.                     retval = _VGAMONO;
  255.                     _cursvar.sizeable = TRUE;
  256.                     _cursvar.mono = TRUE;
  257.                     break;
  258.                 case 1:
  259.                 case 2:
  260.                 case 4:
  261.                 case 9:
  262.                     retval = _VGACOLOR;
  263.                     _cursvar.sizeable = TRUE;
  264.                     _cursvar.mono = FALSE;
  265.                     break;
  266.             }
  267.             break;
  268.         default:
  269.             retval = _CGA;
  270.             _cursvar.mono = FALSE;
  271.             break;
  272.     }
  273.     return (PDC_sanity_check(retval));
  274. #  endif
  275. #endif
  276.  
  277. #ifdef UNIX
  278.     if (set_foreground != NULL && set_background != NULL) /* we have a colour monitor */
  279.         {
  280.         _cursvar.mono = FALSE;
  281.         retval = _UNIX_COLOR;
  282.         }
  283.     else
  284.         {
  285.         _cursvar.mono = TRUE;
  286.         retval = _UNIX_MONO;
  287.         }
  288.     _cursvar.sizeable = FALSE;
  289.     _cursvar.bogus_adapter = FALSE;
  290. return(retval);
  291. #endif
  292. }
  293.